﻿using MB.RuleBase.Common;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Business
{
    public class LocationGoodsBll
    {

        public int GetLocationID(string locationCode)
        {
            try
            {
                int _LocationID = DatabaseExcuteByXmlHelper.NewInstance.ExecuteScalar<int>("LocationGoods", "GetLocationID", locationCode);

                return _LocationID;
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);
                return 0;
            }
        }

        public string GetWarehouseCodeByLoctionID(int locationID)
        {
            try
            {
                string _WarehouseCode = DatabaseExcuteByXmlHelper.NewInstance.ExecuteScalar<string>("LocationGoods", "GetWarehouseCodeByLoctionID", locationID);

                return _WarehouseCode;
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);
                return "";
            }
        }

        public int GetGoodsID(string goodsCode)
        {
            try
            {
                int _GoodsID = DatabaseExcuteByXmlHelper.NewInstance.ExecuteScalar<int>("LocationGoods", "GetGoodsID", goodsCode);

                return _GoodsID;
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);
                return 0;
            }
        }

        public string IsExistGoods(int GOODSID, string warehouseCode, int Status = 1)
        {
            try
            {
                string isLocationCode = DatabaseExcuteByXmlHelper.NewInstance.ExecuteScalar<string>("LocationGoods", "IsExistGoodsInHouse", GOODSID, warehouseCode, Status);

                return isLocationCode;
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);
                return null;
            }
        }

        public string IsExistGoods2(int LocationID, string warehouseCode, int Status = 1)
        {
            try
            {
                string isLocationCode = DatabaseExcuteByXmlHelper.NewInstance.ExecuteScalar<string>("LocationGoods", "IsExistGoodsInHouse2", LocationID, warehouseCode, Status);

                return isLocationCode;
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);
                return null;
            }
        }

        public int SetLocationGoods(int GoodsId, int LocationId, string UserCode, int status)
        {
            try
            {
                int _result = DatabaseExcuteByXmlHelper.NewInstance.ExecuteNonQuery("LocationGoods", "InsertUpdateLocationGoods", GoodsId, LocationId, UserCode, status);

                return _result;
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);
                return 0;
            }
        }

        /// <summary>
        /// 获取商品信息
        /// </summary>
        /// <param name="goodsCode"></param>
        /// <param name="weight"></param>
        /// <returns></returns>
        public Goods GetGoodsByGoodID(int goodsID)
        {
            try
            {
                return DatabaseExcuteByXmlHelper.NewInstance.GetObjectsByXml<Goods>("LocationGoods", "GetGoodsByGoodID", goodsID).FirstOrDefault();


            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);
                return null;
            }
        }
    }
}
